// components/write/index.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    isWriteShow: {
      type: Boolean,
      value: false,
    },
  },

  /**
   * 组件的初始数据
   */
  data: {
    message: "",
    count: 0,
  },

  /**
   * 组件的方法列表
   */
  methods: {
    closeWrite() {
      this.triggerEvent("closeWrite");
      this.setData({
        message: "",
      });
    },

    handleWrite() {
      this.setData({
        count: this.data.message.length,
      });
    },

    submitWrite() {
      if (this.data.message.trim().length === 0) {
        return wx.utils.toast("请输入评论内容");
      }
      this.triggerEvent("submitWrite", this.data.message.trim());
      this.setData({
        message: "",
      });
    },
  },
});
